﻿using Microsoft.Xna.Framework.Graphics;
using JadeEngine.JadeObjects;
using Microsoft.Xna.Framework.Content;

namespace JadeEngine.JadeShaders
{
    public delegate void JadeShaderParameterHandler(Effect effect, JadeObject obj);

    public class JadeShader
    {
        internal string Asset { get; set; }
        internal Effect Effect { get; set;}

        public event JadeShaderParameterHandler SetUserParameters;

        public JadeShader(string asset)
        {
            Asset = asset;
        }

        public void SetTechnique(string technique)
        {
            Effect.CurrentTechnique = Effect.Techniques[technique];
        }

        internal virtual void LoadContent(GraphicsDevice gd, ContentManager cm)
        {
            Effect = cm.Load<Effect>(Asset);
        }

        internal virtual void SetParameters(JadeObject obj)
        {
            if (SetUserParameters != null) SetUserParameters(Effect, obj);
        }
    }
}
